package pers.qianyu.month_202012.date_20201211;

import org.junit.*;

/**
 * 377. 组合总和 Ⅳ
 * https://leetcode-cn.com/problems/combination-sum-iv/
 *
 * @author mizzle rain
 * @date 2020-12-11 17:29
 */
public class CombinationSumFour {
    // 爬楼梯升级版（爬楼梯链接：https://leetcode-cn.com/problems/climbing-stairs/）
    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int i = 1; i < dp.length; i++) {
            for (int num : nums) {
                if (i - num >= 0) {
                    dp[i] += dp[i - num];
                }
            }
        }
        return dp[target];
    }

    @Test
    public void test1() {
        int[] nums = {1, 2, 3};
        int target = 4;
        int result = new CombinationSumFour().combinationSum4(nums, target);
        System.out.println("result = " + result);
    }
}
